#include "waitpid.hpp"

int main()
{
 vector<fun_t> fset;
 fset.push_back(Print1);
 fset.push_back(Print2);
 pid_t pid = fork();
 if(pid == 0)
 {
   int t = 5;
   while(t--)
   {
     printf("I am a child process\n");
     sleep(1);
   }
   exit(0);
 }
 printf("I am a father process and I am waiting\n");
 
 while(1)
 {
    int ret = waitpid(pid,nullptr,WNOHANG);
    if(ret == pid)
    {
      cout << "waiting success" << endl;
      break;
    }
    else if(ret == 0)
    {
      //执行其它功能,调用写好的方法集
      for(auto& f : fset)
        f();
      sleep(1);
    }
    else
    {
      cout << "waiting failed" << endl;
      break;
    }
 }
 
 return 0; 
}
